package com.myapp.EventBus;

import android.os.Handler;

import org.greenrobot.eventbus.EventBus;

public class EventBusUtil {

    private static final EventBus sEventBus = EventBus.builder()
            .strictMethodVerification(true)
            .throwSubscriberException(true)
            .build();

    private EventBusUtil(){}

//    public static boolean isRegistered(Object subscriber){
//       return sEventBus.isRegistered(subscriber);
//    }

    public static void register(Object subscriber) {
        sEventBus.register(subscriber);
    }

    public static void unregister(Object subscriber) {
        sEventBus.unregister(subscriber);
    }

    public static void postSync(Object event) {
        sEventBus.post(event);
    }

    public static void postAsync(final Object event) {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                sEventBus.post(event);
            }
        });
    }

    public static void postSyncSticky(Object event){
        sEventBus.postSticky(event);
    }



    public static void cancel(Object event) {
        sEventBus.cancelEventDelivery(event);
    }
}
